package com.sky.controller.admin;

import com.sky.mapper.MerchantMapper;
import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2024/10/13 15:37
 * @Version 1.0
 */
@RestController
@Api(tags = "店铺营业状态设置")
@RequiredArgsConstructor
public class ShopController {

    private final RedisTemplate redisTemplate;
    private final MerchantMapper merchantMapper;

    private final static String REDIS_STATUS_KEY = "SHOP-STATUS";

    @PutMapping("/admin/shop/{status}")
    @ApiOperation(("设置状态"))
    public Result setStatus(@PathVariable("status") Integer status){
        redisTemplate.opsForValue().set(REDIS_STATUS_KEY,status);
        return Result.success();
    }

    @GetMapping("/admin/shop/status")
    @ApiOperation("获取营业状态")
    public Result getStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get(REDIS_STATUS_KEY);
        return Result.success(status);
    }

    @GetMapping("/user/shop/status")
    @ApiOperation("用户端获取营业状态")
    public Result getShopStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get(REDIS_STATUS_KEY);
        return Result.success(status);
    }



    //  获取店铺电话
    @GetMapping("/user/shop/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result   getMerchantInfo(){
        //  获取唯一商家对象信息
        Merchant merchant = merchantMapper.getById(1L);
        String  shopName = merchant.getShopName();
        String  shopAddress = merchant.getShopAddress();
        String  shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return  Result.success(build);
    }
}